import Opt from '@/components/dt/info/Opt.js'
import dateOpt from '@/biz/option/date.js'
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
let _this = null
class Column extends Opt {

  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    this.all = [
      {
        field: 'userName',
        title: '姓名',
        minWidth: 200,
        align: 'center',

        header: {
          filter: nameOpt.createPeople({
            key: 'userName',
            title: '姓名',
            to: (info) => {
              return {
                userName: info.userName
              }
            }
          })
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: `${params.row.userName}（${params.row.workNo}）`
            })
          }
        }

      },
      {
        field: 'title',
        title: '标题',
        minWidth: 300,
        align: 'center',
        header: {
          filter: {
            title: '标题',
            key: 'title',
            placeholder: '请输入标题',
            input: {}
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.btn(_this, h, {
              title: params.row.title ? params.row.title : '-',
              event: 'videoClick',
              data: params.row
            })
          }
        }
      },
      {
        title: '发布时间',
        field: 'dyCreateTime',
        minWidth: 180,

        header: {
          filter: dateOpt.range({
            title: '发布时间',
            startKey: 'releaseTimeStart',
            endKey: 'releaseTimeEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.releaseTimeStart, val
                  .releaseTimeEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('认购日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.releaseTimeStart, val
                .releaseTimeEnd).Y >= 2)
            }
          }),
        },
      },
      {
        title: '更新时间',
        field: 'createTime',
        minWidth: 150,
      },
      {
        title: '总播放',
        field: 'playCount',
        minWidth: 90,
        remoteSort: true,
      },
      {
        title: '总点赞',
        field: 'diggCount',
        minWidth: 90,
        remoteSort: true,
      },
      {
        title: '总评论',
        field: 'commentCount',
        minWidth: 90,
        remoteSort: true,
      },
      {
        title: '总分享',
        field: 'shareCount',
        minWidth: 90,
        remoteSort: true,
      },

      {
        title: '所属事业部',
        field: 'orgDivisionName',
        minWidth: 150,
      }, {
        title: '所属子公司',
        field: 'orgCompanyName',
        minWidth: 150,
      }, {
        title: '所属事业处',
        field: 'orgOfficeName',
        minWidth: 150,
      },
    ]
  }

}

export default Column